package org.bikelab.se3.mr;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Text;

public class ContextIndexedTableWriter extends TableReducer<Text, Text, Text> {
    public void reduce(Text key, Iterable<Text> values, Context context)
            throws IOException, InterruptedException {
		StringBuilder sb = new StringBuilder();
		Iterator<Text> list = values.iterator();
		while(list.hasNext()) {
			sb.append(list.next().toString());
			sb.append("\n");
		}
		Put put = new Put(key.getBytes());
		put.add(Bytes.toBytes("content"), Bytes.toBytes("ntriple"), Bytes.toBytes(sb.toString()));
//        System.out.println(String.format("stats :   key : %d,  count : %d", Bytes.toInt(key.get()), sum));
        context.write(key, put);
    }
}
